# 用户操作的主界面
from PyQt5 import QtWidgets
import temp, mysql


class user_main(QtWidgets.QMainWindow):
    def __init__(self):
        super(user_main, self).__init__()
        self.card = temp.card

    def setupUI(self):
        self.setWindowTitle("用户界面")
        self.setGeometry(100, 100, 300, 300)
        self.Qbutton1()
        self.Qbutton2()
        self.Qbutton3()
        self.Qbutton4()
        self.Qbutton5()
        self.Qbutton6()

    def Qbutton1(self):
        qbutton = QtWidgets.QPushButton(self)
        qbutton.setText("查询余额")
        qbutton.setGeometry(30, 30, 100, 30)
        qbutton.clicked.connect(self.Qbutton1_click)

    def Qbutton1_click(self):
        print(self.card)
        sql = "SELECT * FROM ATM.User where card = '{0}' ".format(self.card)
        result = mysql.select_sql(sql)
        money = result['money']
        message = "查询卡号为" + self.card + ",此卡当前余额为" + str(money) + "元"
        self.msg = QtWidgets.QMessageBox(QtWidgets.QMessageBox.Information, "信息", message)
        return self.msg.show()

    def Qbutton2(self):
        qbutton = QtWidgets.QPushButton(self)
        qbutton.setText("取款")
        qbutton.setGeometry(30, 100, 100, 30)
        qbutton.clicked.connect(self.Qbutton2_click)

    # 新建一个取款窗口，本窗口禁止操作
    def Qbutton2_click(self):
        from user_qukuan import user_qukuan
        self.qukuan = user_qukuan()
        self.qukuan.setupUI()
        self.qukuan.show()
        self.hide()

    def Qbutton3(self):
        qbutton = QtWidgets.QPushButton(self)
        qbutton.setText("ATM转账")
        qbutton.setGeometry(30, 170, 100, 30)
        qbutton.clicked.connect(self.Qbutton3_click)

    def Qbutton3_click(self):
        from user_ATM import user_atm
        self.atm = user_atm()
        self.atm.setupUI()
        self.atm.show()
        self.hide()

    def Qbutton4(self):
        qbutton = QtWidgets.QPushButton(self)
        qbutton.setText("历史记录")
        qbutton.setGeometry(30, 240, 100, 30)
        qbutton.clicked.connect(self.Qbutton4_click)

    def Qbutton4_click(self):
        from user_history import user_history
        self.history = user_history()
        self.history.setupUI()
        self.history.show()
        self.hide()

    def Qbutton5(self):
        qbutton = QtWidgets.QPushButton(self)
        qbutton.setText("修改密码")
        qbutton.setGeometry(150, 170, 100, 30)
        qbutton.clicked.connect(self.Qbutton5_click)

    def Qbutton5_click(self):
        from user_update_password import user_update_password
        self.user_password = user_update_password()
        self.user_password.setupUI()
        self.user_password.show()
        self.hide()

    def Qbutton6(self):
        qbutton = QtWidgets.QPushButton(self)
        qbutton.setText("退卡")
        qbutton.setGeometry(150, 240, 100, 30)
        qbutton.clicked.connect(self.Qbutton6_click)

    def Qbutton6_click(self):
        from user_ui import User_UI
        self.user_ui = User_UI()
        self.user_ui.setupUI()
        self.user_ui.show()
        self.close()
